package com.situ.team5.kzq.power.dao;

import com.situ.team5.pojo.Users;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
@Mapper
public interface QxDAO {
    //职位表和用户表的连接查询
    @Select("select u.*, c.* from users u inner join config_major c on \n" +
            "u.u_major_id=c.major_id")
    List<Map> User_config_majorSelectAll();


    @Select("select * from config_major ")
    List<Map> config_majorSelectALL();


    @Transactional
    @Insert("<script>"+
            "insert into users\n" +
            " ("+
            "\t\t\t<if test=\"u_name != null\">u_name,</if>\n" +
            "\t\t\t<if test=\"u_true_name != null\">u_true_name,</if>\n" +
            "\t\t\t<if test=\"u_password != null\">u_password,</if>\n" +
            "\t\t\t<if test=\"u_major_id != null\">u_major_id</if>\n" +
            " )"+
           " values("+
            "\t\t\t<if test=\"u_name != null\">#{u_name},</if>\n" +
            "\t\t\t<if test=\"u_true_name != null\">#{u_true_name},</if>\n" +
            "\t\t\t<if test=\"u_password != null\">#{u_password},</if>\n" +
            "\t\t\t<if test=\"u_major_id != null\">#{u_major_id}</if>\n" +
            " )"+
          "</script>")
    void users_Insert(Users u);
    @Transactional
@Update("Update users set u_name=#{u_name},u_true_name=#{u_true_name}," +
        "u_password=#{u_password},u_major_id=#{u_major_id} where u_id=#{u_id}")
    void users_Update2(Users e);


@Select("select u.*, c.* from users u inner join config_major c on"+
        " u.u_major_id=c.major_id where u.u_id=#{value}")
    Map users_Update(int id);
//通过id删除用户表数据
@Transactional
@Delete("delete from users where u_id=#{value}")
    void users_Delete(int id);
}
